<!DOCTYPE HTML>

<html>
    <head>
        <script type="application/ld+json">
    {
        "@context" : "http://schema.org",
        "@type" : "BlogPosting",
        "mainEntityOfPage": {
             "@type": "WebPage",
             "@id": "\/blog\/"
        },
        "articleSection" : "blog",
        "name" : "实现拖拽上传文件到又拍云存储",
        "headline" : "实现拖拽上传文件到又拍云存储",
        "description" : "mff的个人博客",
        "inLanguage" : "en",
        "author" : "",
        "creator" : "",
        "publisher": "",
        "accountablePerson" : "",
        "copyrightHolder" : "",
        "copyrightYear" : "2020",
        "datePublished": "2020-04-28 00:00:00 \x2b0000 UTC",
        "dateModified" : "2020-04-28 00:00:00 \x2b0000 UTC",
        "url" : "\/blog\/blog\/%E5%8F%88%E6%8B%8D%E4%BA%91%E5%AD%98%E5%82%A8%E5%AE%9E%E7%8E%B0%E6%8B%96%E6%8B%BD%E4%B8%8A%E4%BC%A0\/",
        "wordCount" : "224",
        "keywords" : [ "tutorial","Blog" ]
    }
    </script>
        
            
                <title>实现拖拽上传文件到又拍云存储</title>
            
        

        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="generator" content="Hugo 0.69.0" />
        
  
    
  

  

  <link rel="apple-touch-icon-precomposed" href='/blog/favicon/apple-touch-icon-precomposed.png'>
  <link rel="icon" href='/blog/favicon/favicon.png'>
  
  <meta name="msapplication-TileColor" content="#da532c">
  <meta name="msapplication-TileImage" content='/favicon/mstile.png'>
  <meta name="application-name" content="mff blog">
  <meta name="msapplication-tooltip" content="">
  <meta name="msapplication-config" content='/favicon/ieconfig.xml'>



        
            <meta name="author" content="mff">
        
        
            <meta name="description" content="mff的个人博客">
        

        <meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="实现拖拽上传文件到又拍云存储"/>
<meta name="twitter:description" content="mff的个人博客"/>

        <meta property="og:title" content="实现拖拽上传文件到又拍云存储" />
<meta property="og:description" content="mff的个人博客" />
<meta property="og:type" content="article" />
<meta property="og:url" content="/blog/blog/%E5%8F%88%E6%8B%8D%E4%BA%91%E5%AD%98%E5%82%A8%E5%AE%9E%E7%8E%B0%E6%8B%96%E6%8B%BD%E4%B8%8A%E4%BC%A0/" />
<meta property="article:published_time" content="2020-04-28T00:00:00+00:00" />
<meta property="article:modified_time" content="2020-04-28T00:00:00+00:00" />

        <meta property="og:image" content="/blog//images/logo.png">
        <meta property="og:image:type" content="image/png">
        <meta property="og:image:width" content="512">
        <meta property="og:image:height" content="512">
        <meta itemprop="name" content="实现拖拽上传文件到又拍云存储">
<meta itemprop="description" content="mff的个人博客">
<meta itemprop="datePublished" content="2020-04-28T00:00:00&#43;00:00" />
<meta itemprop="dateModified" content="2020-04-28T00:00:00&#43;00:00" />
<meta itemprop="wordCount" content="224">



<meta itemprop="keywords" content="tutorial," />
        

        
            
        

        
        
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/atom-one-light.min.css">
            <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway:400,800,900|Source+Sans+Pro:400,700">
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.25/jquery.fancybox.min.css">
            <link rel="stylesheet" href="/blog/css/main.css">
            <link rel="stylesheet" href="/blog/css/add-on.css">
            <link rel="stylesheet" href="/blog/css/academicons.min.css">
        

        
            
                
            
        


  
    
    <link href='//cdn.bootcss.com/highlight.js/9.11.0/styles/github.min.css' rel='stylesheet' type='text/css' />
  


      
    </head>
    <body>

      
      <div id="wrapper">

    
    
<header id="header">
    
      <h1><a href="/blog/">blog</a></h1>
    

    <nav class="links">
        <ul>
            
                <li>
                    <a href="/blog/">
                            <i class="fa fa-home">&nbsp;</i>主页
                    </a>
                </li>
            
                <li>
                    <a href="/blog/blog/">
                            <i class="fa fa-newspaper-o">&nbsp;</i>Blog笔记
                    </a>
                </li>
            
                <li>
                    <a href="https://mff-project.gitee.io/hugoblog/posts/%E4%B8%AA%E4%BA%BA%E7%AE%80%E5%8E%86/">
                            <i class="fa fa-id-card-o">&nbsp;</i>个人简历
                    </a>
                </li>
            
                <li>
                    <a href="/blog/itemized/">
                            <i class="fa fa-list">&nbsp;</i>最近项目
                    </a>
                </li>
            
                <li>
                    <a href="/blog/contact/">
                            <i class="fa fa-envelope-o">&nbsp;</i>联系我
                    </a>
                </li>
            
        </ul>
    </nav>
    <nav class="main">
        <ul>
            
            <li id="share-nav" class="share-menu" style="display:none;">
                <a class="fa-share-alt" href="#share-menu">Share</a>
            </li>
            
            <li class="search">
                <a class="fa-search" href="#search">Search</a>
                <form id="search" method="get" action="//google.com/search">
                    <input type="text" name="q" placeholder="Search" />
                    <input type="hidden" name="as_sitesearch" value="/blog/">
                </form>
            </li>
            <li class="menu">
                <a class="fa-bars" href="#menu">Menu</a>
            </li>
        </ul>
    </nav>
</header>


<section id="menu">

    
        <section>
            <form class="search" method="get" action="//google.com/search">
                <input type="text" name="q" placeholder="Search" />
                <input type="hidden" name="as_sitesearch" value="/blog/">
            </form>
        </section>

    
        <section>
            <ul class="links">
                
                    <li>
                        <a href="/blog/">
                            <h3>
                                <i class="fa fa-home">&nbsp;</i>主页
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/blog/">
                            <h3>
                                <i class="fa fa-newspaper-o">&nbsp;</i>Blog笔记
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="https://mff-project.gitee.io/hugoblog/posts/%E4%B8%AA%E4%BA%BA%E7%AE%80%E5%8E%86/">
                            <h3>
                                <i class="fa fa-id-card-o">&nbsp;</i>个人简历
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/itemized/">
                            <h3>
                                <i class="fa fa-list">&nbsp;</i>最近项目
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/contact/">
                            <h3>
                                <i class="fa fa-envelope-o">&nbsp;</i>联系我
                            </h3>
                        </a>
                    </li>
                
            </ul>
        </section>

    
        <section class="recent-posts">
            <div class="mini-posts">
                <header>
                    <h3>Recent Posts</h3>
                </header>
                

                
                    
                

                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/fastdfs%E9%85%8D%E7%BD%AE%E5%8F%8A%E4%BB%8B%E7%BB%8D/">FastDFS配置及介绍</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-08-27'>
                                    August 27, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/orm%E5%B8%B8%E8%A7%84%E6%93%8D%E4%BD%9C%E9%87%8D%E7%82%B9/">orm常规操作</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-28'>
                                    July 28, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98%E6%93%8D%E4%BD%9C/">支付宝沙箱支付操作</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-28'>
                                    July 28, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/%E8%85%BE%E8%AE%AF%E7%9F%AD%E4%BF%A1%E5%8F%91%E9%80%81%E9%AA%8C%E8%AF%81%E7%A0%81/">腾讯短信发送验证码</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-28'>
                                    July 28, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/flask&#43;vue%E5%AE%9E%E7%8E%B0%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB/">flask&#43;vue实现前后端分离</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-26'>
                                    July 26, 2020</time>
                            </header>
                            

                        </article>
                

                
                    <a href=
                        
                            /blog/
                        
                        class="button">View more posts</a>
                
            </div>
        </section>

    
        
</section>

    <section id="share-menu">
    <section id="social-share-nav">
        <ul class="links">
            <header>
                <h3>Share this post <i class="fa fa-smile-o"></i></h3>
            </header>
            



<li>
  <a href="//twitter.com/share?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f&amp;text=%e5%ae%9e%e7%8e%b0%e6%8b%96%e6%8b%bd%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e5%88%b0%e5%8f%88%e6%8b%8d%e4%ba%91%e5%ad%98%e5%82%a8&amp;via=" target="_blank" class="share-btn twitter">
    <i class="fa fa-twitter"></i>
    <p>Twitter</p>
    </a>
</li>




<li>
  <a href="//plus.google.com/share?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f" target="_blank" class="share-btn google-plus">
    <i class="fa fa-google-plus"></i>
    <p>Google+</p>
  </a>
</li>





<li>
  <a href="//www.facebook.com/sharer/sharer.php?u=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f" target="_blank" class="share-btn facebook">
    <i class="fa fa-facebook"></i>
    <p>Facebook</p>
    </a>
</li>




<li>
  <a href="//reddit.com/submit?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f&amp;title=%e5%ae%9e%e7%8e%b0%e6%8b%96%e6%8b%bd%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e5%88%b0%e5%8f%88%e6%8b%8d%e4%ba%91%e5%ad%98%e5%82%a8" target="_blank" class="share-btn reddit">
    <i class="fa fa-reddit-alien"></i>
    <p>Reddit</p>
  </a>
</li>




<li>
  <a href="//www.linkedin.com/shareArticle?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f&amp;title=%e5%ae%9e%e7%8e%b0%e6%8b%96%e6%8b%bd%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e5%88%b0%e5%8f%88%e6%8b%8d%e4%ba%91%e5%ad%98%e5%82%a8" target="_blank" class="share-btn linkedin">
      <i class="fa fa-linkedin"></i>
      <p>LinkedIn</p>
    </a>
</li>




<li>
  <a href="//www.stumbleupon.com/submit?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f&amp;title=%e5%ae%9e%e7%8e%b0%e6%8b%96%e6%8b%bd%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e5%88%b0%e5%8f%88%e6%8b%8d%e4%ba%91%e5%ad%98%e5%82%a8" target="_blank" class="share-btn stumbleupon">
    <i class="fa fa-stumbleupon"></i>
    <p>StumbleUpon</p>
  </a>
</li>




<li>
  <a href="//www.pinterest.com/pin/create/button/?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f&amp;description=%e5%ae%9e%e7%8e%b0%e6%8b%96%e6%8b%bd%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e5%88%b0%e5%8f%88%e6%8b%8d%e4%ba%91%e5%ad%98%e5%82%a8" target="_blank" class="share-btn pinterest">
    <i class="fa fa-pinterest-p"></i>
    <p>Pinterest</p>
  </a>
</li>




<li>
  <a href="mailto:?subject=Check out this post by mff&amp;body=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f" target="_blank" class="share-btn email">
    <i class="fa fa-envelope"></i>
    <p>Email</p>
  </a>
</li>


        </ul>
    </section>
</section>

    
    <div id="main">
        
        
        <article class="post">
  <header>
    <div class="title">
        
            <h1><a href="/blog/blog/%E5%8F%88%E6%8B%8D%E4%BA%91%E5%AD%98%E5%82%A8%E5%AE%9E%E7%8E%B0%E6%8B%96%E6%8B%BD%E4%B8%8A%E4%BC%A0/">实现拖拽上传文件到又拍云存储</a></h1>
            
        
        
            <p>mff的个人博客</p>
        
    </div>
    <div class="meta">
        

        <time class="published"
            datetime='2020-04-28'>
            April 28, 2020</time>
        <span class="author">mff</span>
        
            <p>2 minute read</p>
        
        
    </div>
</header>


  
    <section id="social-share">
      <ul class="icons">
        



<li>
  <a href="//twitter.com/share?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f&amp;text=%e5%ae%9e%e7%8e%b0%e6%8b%96%e6%8b%bd%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e5%88%b0%e5%8f%88%e6%8b%8d%e4%ba%91%e5%ad%98%e5%82%a8&amp;via=" target="_blank" class="share-btn twitter">
    <i class="fa fa-twitter"></i>
    <p>Twitter</p>
    </a>
</li>




<li>
  <a href="//plus.google.com/share?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f" target="_blank" class="share-btn google-plus">
    <i class="fa fa-google-plus"></i>
    <p>Google+</p>
  </a>
</li>





<li>
  <a href="//www.facebook.com/sharer/sharer.php?u=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f" target="_blank" class="share-btn facebook">
    <i class="fa fa-facebook"></i>
    <p>Facebook</p>
    </a>
</li>




<li>
  <a href="//reddit.com/submit?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f&amp;title=%e5%ae%9e%e7%8e%b0%e6%8b%96%e6%8b%bd%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e5%88%b0%e5%8f%88%e6%8b%8d%e4%ba%91%e5%ad%98%e5%82%a8" target="_blank" class="share-btn reddit">
    <i class="fa fa-reddit-alien"></i>
    <p>Reddit</p>
  </a>
</li>




<li>
  <a href="//www.linkedin.com/shareArticle?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f&amp;title=%e5%ae%9e%e7%8e%b0%e6%8b%96%e6%8b%bd%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e5%88%b0%e5%8f%88%e6%8b%8d%e4%ba%91%e5%ad%98%e5%82%a8" target="_blank" class="share-btn linkedin">
      <i class="fa fa-linkedin"></i>
      <p>LinkedIn</p>
    </a>
</li>




<li>
  <a href="//www.stumbleupon.com/submit?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f&amp;title=%e5%ae%9e%e7%8e%b0%e6%8b%96%e6%8b%bd%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e5%88%b0%e5%8f%88%e6%8b%8d%e4%ba%91%e5%ad%98%e5%82%a8" target="_blank" class="share-btn stumbleupon">
    <i class="fa fa-stumbleupon"></i>
    <p>StumbleUpon</p>
  </a>
</li>




<li>
  <a href="//www.pinterest.com/pin/create/button/?url=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f&amp;description=%e5%ae%9e%e7%8e%b0%e6%8b%96%e6%8b%bd%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e5%88%b0%e5%8f%88%e6%8b%8d%e4%ba%91%e5%ad%98%e5%82%a8" target="_blank" class="share-btn pinterest">
    <i class="fa fa-pinterest-p"></i>
    <p>Pinterest</p>
  </a>
</li>




<li>
  <a href="mailto:?subject=Check out this post by mff&amp;body=%2fblog%2fblog%2f%25E5%258F%2588%25E6%258B%258D%25E4%25BA%2591%25E5%25AD%2598%25E5%2582%25A8%25E5%25AE%259E%25E7%258E%25B0%25E6%258B%2596%25E6%258B%25BD%25E4%25B8%258A%25E4%25BC%25A0%2f" target="_blank" class="share-btn email">
    <i class="fa fa-envelope"></i>
    <p>Email</p>
  </a>
</li>


      </ul>
    </section>
  

  

  <div id="content">
    <p>先看一下流程图</p>
<p>​	<img src="/blog/img/imgs/%E5%8F%88%E6%8B%8D%E4%BA%91%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E6%B5%81%E7%A8%8B%E5%9B%BE.jpg" alt="又拍云文件上传流程图"></p>
<hr>
<ol>
<li>
<p>下载upyun组件</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cmd" data-lang="cmd">pip install upyun
</code></pre></div><hr>
</li>
<li>
<p>进入又拍云官网(<a href="https://www.upyun.com/">https://www.upyun.com/</a>)</p>
<ol>
<li>
<p>完成又拍云注册并实名认证</p>
</li>
<li>
<p>进入控制台打开云存储</p>
</li>
<li>
<p>点击创建服务</p>
<p><img src="/blog/img/imgs/Snipaste_2020-05-09_21-08-56.png" alt="1589029704343"></p>
</li>
<li>
<p>服务名称为唯一</p>
<p><img src="/blog/img/imgs/Snipaste_2020-05-09_21-10-49.png" alt="1589029859282"></p>
</li>
<li>
<p>(重点)点击新建操作员,名称也是唯一，密码自动生成，并点击复制权限三个全部勾选</p>
<p><img src="/blog/img/imgs/Snipaste_2020-05-09_21-19-43.png" alt="1589029909431"></p>
</li>
<li>
<p>点击创建</p>
</li>
</ol>
</li>
</ol>
<hr>
<ol start="3">
<li>
<p>后端(django)接收图片并上传到又拍云</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#75715e"># 又拍云存储</span>
<span style="color:#f92672">from</span> rest_framework.views <span style="color:#f92672">import</span> APIView
<span style="color:#f92672">import</span> upyun
<span style="color:#f92672">import</span> uuid
   
<span style="color:#66d9ef">class</span> <span style="color:#a6e22e">UpYun</span>(APIView):
    <span style="color:#75715e"># 文件post无大小限制</span>
    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">post</span>(self,request):
        <span style="color:#75715e"># 获取文件</span>
        myfile <span style="color:#f92672">=</span> request<span style="color:#f92672">.</span>FILES<span style="color:#f92672">.</span>get(<span style="color:#e6db74">&#39;file&#39;</span>)
        <span style="color:#75715e"># 将接收来的文件名替换为UUID自动生成文件名，降低图片重名操作</span>
        myfilename <span style="color:#f92672">=</span> str(uuid<span style="color:#f92672">.</span>uuid3(uuid<span style="color:#f92672">.</span>uuid1(), myfile<span style="color:#f92672">.</span>name)) <span style="color:#f92672">+</span> <span style="color:#e6db74">&#39;.jpg&#39;</span>
        <span style="color:#75715e"># 新建又拍云实例,第一个参数为空间名称,第二个参数为操作员名称,三为密码</span>
        up <span style="color:#f92672">=</span> upyun<span style="color:#f92672">.</span>UpYun(<span style="color:#e6db74">&#39;mff-project-md&#39;</span>,<span style="color:#e6db74">&#39;mff&#39;</span>,<span style="color:#e6db74">&#39;y3ExbYwApYBGobRlTgqqeY3yRAh7eba0&#39;</span>)
        <span style="color:#75715e"># 声明头部信息(实际上是又拍云自定的头部信息)</span>
        headers <span style="color:#f92672">=</span> {<span style="color:#e6db74">&#39;x-gmkerl-rotate&#39;</span>:<span style="color:#e6db74">&#39;auto&#39;</span>}
        <span style="color:#75715e"># 上传图片</span>
        <span style="color:#66d9ef">for</span> chunk <span style="color:#f92672">in</span> myfile<span style="color:#f92672">.</span>chunks():
            res <span style="color:#f92672">=</span> up<span style="color:#f92672">.</span>put(myfilename,chunk,checksum<span style="color:#f92672">=</span>True,headers<span style="color:#f92672">=</span>headers)
           
        <span style="color:#66d9ef">return</span> Response({<span style="color:#e6db74">&#39;filename&#39;</span>:myfilename})
</code></pre></div></li>
<li>
<p>记得设置好接口路由</p>
</li>
</ol>
<hr>
<ol start="5">
<li>
<p>postman测试成功返回</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-json" data-lang="json">{<span style="color:#960050;background-color:#1e0010">&#39;filename&#39;:</span> <span style="color:#960050;background-color:#1e0010">&#39;2906bd7f-d604-3c2f-a357-3c62b3a8bd08.jpg&#39;</span>}
</code></pre></div></li>
</ol>
<hr>
<ol start="6">
<li>
<p>前端(vue)实现拖拽上传文件并提交给写好的后端接口</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-vue" data-lang="vue">&lt;<span style="color:#f92672">template</span>&gt;
 &lt;<span style="color:#f92672">div</span>&gt;
        &lt;<span style="color:#f92672">table</span>&gt;
            <span style="color:#75715e">&lt;!--</span> <span style="color:#a6e22e">实时展示</span> <span style="color:#f92672">--&gt;</span>
            &lt;<span style="color:#f92672">Avatar</span> <span style="color:#f92672">:src</span><span style="color:#e6db74">=&#34;src&#34;</span> <span style="color:#f92672">:width</span><span style="color:#e6db74">=&#34;100&#34;</span> <span style="color:#a6e22e">fit</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;fill&#34;</span>&gt;&lt;/<span style="color:#f92672">Avatar</span>&gt;
            &lt;<span style="color:#f92672">tr</span>&gt;
                    &lt;<span style="color:#f92672">td</span>&gt;
                        <span style="color:#75715e">&lt;!--</span> <span style="color:#a6e22e">设置图片拖拽区域</span> <span style="color:#f92672">--&gt;</span>
                        &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;upload&#34;</span> <span style="color:#f92672">v-show</span><span style="color:#e6db74">=&#34;type&#34;</span>&gt;<span style="color:#a6e22e">请将图片拖拽至此处</span>&lt;/<span style="color:#f92672">div</span>&gt;
                    &lt;/<span style="color:#f92672">td</span>&gt;
                    &lt;<span style="color:#f92672">td</span>&gt;
                        <span style="color:#75715e">&lt;!--</span> <span style="color:#a6e22e">绑定又拍云方法</span> <span style="color:#f92672">--&gt;</span>
                        &lt;<span style="color:#f92672">input</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;file&#34;</span> <span style="color:#f92672">@change</span><span style="color:#e6db74">=&#34;upload_upyun&#34;</span> <span style="color:#f92672">v-show</span><span style="color:#e6db74">=&#34;type&#34;</span>&gt;
                    &lt;/<span style="color:#f92672">td</span>&gt;
                &lt;/<span style="color:#f92672">tr</span>&gt;
        &lt;/<span style="color:#f92672">table</span>&gt;
    &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
&lt;<span style="color:#f92672">script</span>&gt;
    <span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> {
        <span style="color:#a6e22e">data</span>(){
            <span style="color:#66d9ef">return</span>{
                <span style="color:#a6e22e">src</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;&#39;</span>,
            }
        },
        <span style="color:#75715e">// 钩子
</span><span style="color:#75715e"></span>        <span style="color:#a6e22e">mounted</span><span style="color:#f92672">:</span><span style="color:#66d9ef">function</span>(){
            <span style="color:#75715e">// 注册拖拽容器
</span><span style="color:#75715e"></span>            <span style="color:#66d9ef">let</span> <span style="color:#a6e22e">upload</span> <span style="color:#f92672">=</span> document.<span style="color:#a6e22e">querySelector</span>(<span style="color:#e6db74">&#39;.upload&#39;</span>);
            <span style="color:#75715e">// 声明监听事件
</span><span style="color:#75715e"></span>            <span style="color:#75715e">// dragenter 开始摁下鼠标
</span><span style="color:#75715e"></span>            <span style="color:#a6e22e">upload</span>.<span style="color:#a6e22e">addEventListener</span>(<span style="color:#e6db74">&#39;dragenter&#39;</span>,<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">onDrag</span>,<span style="color:#66d9ef">false</span>);
            <span style="color:#75715e">// dragover 悬停在拖拽区域
</span><span style="color:#75715e"></span>            <span style="color:#a6e22e">upload</span>.<span style="color:#a6e22e">addEventListener</span>(<span style="color:#e6db74">&#39;dragover&#39;</span>,<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">onDrag</span>,<span style="color:#66d9ef">false</span>);
            <span style="color:#75715e">// drop 松开鼠标
</span><span style="color:#75715e"></span>            <span style="color:#a6e22e">upload</span>.<span style="color:#a6e22e">addEventListener</span>(<span style="color:#e6db74">&#39;drop&#39;</span>,<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">onDrop</span>,<span style="color:#66d9ef">false</span>);
        },
        <span style="color:#a6e22e">methods</span><span style="color:#f92672">:</span>{
            <span style="color:#75715e">// 监听用户鼠标
</span><span style="color:#75715e"></span>            <span style="color:#75715e">// 点选摁住拖拽
</span><span style="color:#75715e"></span>            <span style="color:#a6e22e">onDrag</span>(<span style="color:#a6e22e">e</span>){
                <span style="color:#a6e22e">e</span>.<span style="color:#a6e22e">stopPropagation</span>();
                <span style="color:#a6e22e">e</span>.<span style="color:#a6e22e">preventDefault</span>();
            },
            <span style="color:#75715e">// 松开鼠标
</span><span style="color:#75715e"></span>            <span style="color:#a6e22e">onDrop</span>(<span style="color:#a6e22e">e</span>){
                <span style="color:#a6e22e">e</span>.<span style="color:#a6e22e">stopPropagation</span>();
                <span style="color:#a6e22e">e</span>.<span style="color:#a6e22e">preventDefault</span>();
                <span style="color:#75715e">// 将图片传送到自定义图片上传方法里
</span><span style="color:#75715e"></span>                <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">upload_upyun</span>(<span style="color:#a6e22e">e</span>.<span style="color:#a6e22e">dataTransfer</span>.<span style="color:#a6e22e">files</span>);
            },
            <span style="color:#75715e">// 又拍云拖拽上传方法
</span><span style="color:#75715e"></span>            <span style="color:#a6e22e">upload_upyun</span><span style="color:#f92672">:</span><span style="color:#66d9ef">function</span>(<span style="color:#a6e22e">files</span>){
                <span style="color:#75715e">// 获取拖拽的文件
</span><span style="color:#75715e"></span>                <span style="color:#66d9ef">let</span> <span style="color:#a6e22e">file</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">files</span>[<span style="color:#ae81ff">0</span>];
             <span style="color:#75715e">// 声明参数
</span><span style="color:#75715e"></span>                <span style="color:#66d9ef">let</span> <span style="color:#a6e22e">param</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">FormData</span>();
                <span style="color:#a6e22e">param</span>.<span style="color:#a6e22e">append</span>(<span style="color:#e6db74">&#39;file&#39;</span>,<span style="color:#a6e22e">file</span>);
                <span style="color:#75715e">// 声明头部信息
</span><span style="color:#75715e"></span>                <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">config</span> <span style="color:#f92672">=</span> {
                    <span style="color:#a6e22e">headers</span><span style="color:#f92672">:</span>{<span style="color:#e6db74">&#39;Content-Type&#39;</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;multipart/form-data&#39;</span>}
                }
                <span style="color:#75715e">// 发送请求获取参数
</span><span style="color:#75715e"></span>                <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">axios</span>.<span style="color:#a6e22e">post</span>(<span style="color:#e6db74">&#39;http://127.0.0.1:8000/upyun/&#39;</span>,<span style="color:#a6e22e">param</span>,<span style="color:#a6e22e">config</span>).<span style="color:#a6e22e">then</span>((<span style="color:#a6e22e">result</span>)=&gt;{
                    <span style="color:#75715e">// 打印日志
</span><span style="color:#75715e"></span>                    <span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">result</span>);
                    <span style="color:#75715e">// 赋值图片链接给src
</span><span style="color:#75715e"></span>                    <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">src</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;http://mff-project-md.test.upcdn.net/&#39;</span> <span style="color:#f92672">+</span> <span style="color:#a6e22e">result</span>.<span style="color:#a6e22e">data</span>.<span style="color:#a6e22e">filename</span>;
                })
            }
        }
    }
&lt;/<span style="color:#f92672">script</span>&gt;
&lt;<span style="color:#f92672">style</span>&gt;
    <span style="color:#75715e">/* 样式 */</span>
    .<span style="color:#a6e22e">upload</span>{
        <span style="color:#a6e22e">margin</span> <span style="color:#f92672">:</span> <span style="color:#ae81ff">100</span><span style="color:#a6e22e">px</span>;
        <span style="color:#a6e22e">width</span> <span style="color:#f92672">:</span> <span style="color:#ae81ff">300</span><span style="color:#a6e22e">px</span>;
        <span style="color:#a6e22e">height</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">150</span><span style="color:#a6e22e">px</span>;
        <span style="color:#a6e22e">border</span> <span style="color:#f92672">:</span> <span style="color:#ae81ff">2</span><span style="color:#a6e22e">px</span> <span style="color:#a6e22e">dashed</span> <span style="color:#a6e22e">rgb</span>(<span style="color:#ae81ff">59</span>, <span style="color:#ae81ff">58</span>, <span style="color:#ae81ff">58</span>);
        <span style="color:#a6e22e">margin</span><span style="color:#f92672">:</span><span style="color:#ae81ff">0</span> <span style="color:#a6e22e">auto</span>;
        <span style="color:#a6e22e">line</span><span style="color:#f92672">-</span><span style="color:#a6e22e">height</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">150</span><span style="color:#a6e22e">px</span>;
        <span style="color:#a6e22e">text</span><span style="color:#f92672">-</span><span style="color:#a6e22e">align</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">center</span>;
    }
&lt;/<span style="color:#f92672">style</span>&gt;
</code></pre></div><hr>
<ol start="7">
<li>这样简单的一个拖拽文件上传就做好了，也可以自己加一些存储到本地数据库，实现状态保持等操作</li>
</ol>
</li>
</ol>
  </div>

  <footer>
    <ul class="stats">
  <li class="categories">
    <ul>
        
            
            
                <i class="fa fa-folder"></i>
                
                
                <li><a class="article-category-link" href="/blog/blog/categories/hugo">Hugo</a></li>
                
            
        
    </ul>
  </li>
  <li class="tags">
    <ul>
        
            
            
                <i class="fa fa-tags"></i>
                
                
                <li><a class="article-category-link" href="/blog/blog/tags/tutorial">tutorial</a></li>
                
            
        
    </ul>
  </li>
</ul>

  </footer>

</article>

    <article class="post">
        <div id="disqus_thread"></div>
<script type="application/javascript">
    var disqus_config = function () {
    
    
    
    };
    (function() {
        if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
            document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
            return;
        }
        var d = document, s = d.createElement('script'); s.async = true;
        s.src = '//' + "shortname" + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
    </article>


<ul class="actions pagination">
    
        <li><a href="/blog/blog/%E5%AE%9E%E7%8E%B0%E6%A8%A1%E6%8B%9F%E6%B3%A8%E5%86%8C%E7%99%BB%E5%BD%95/"
                class="button big previous">实现模拟注册及登录</a></li>
    

    
        <li><a href="/blog/blog/%E5%9B%BE%E7%89%87%E5%8E%8B%E7%BC%A9%E5%8A%A0%E6%B0%B4%E5%8D%B0%E6%93%8D%E4%BD%9C/"
                class="button big next">图片的压缩及加水印</a></li>
    
</ul>


    </div>
    
<section id="sidebar">

  
  <section id="intro">
    
    
      
        <a href='/blog/'><img src="/blog/img/main/touxiang3.jpg" class="intro-circle" width="150px" alt="Hugo Future Imperfect" /></a>
      
    
    
      <header>
        <h2>mff</h2>
        <p>Effort is for money, and money is life!</p>
      </header>
    
    
      <ul class="icons">
        
          
    <li><a href="/blog/blog/index.xml" type="application/rss+xml" target="_blank" title="RSS" class="fa fa-rss"></a></li>


        
        












































































  <li><a href="mailto:2980738482@qq.com" title="Email" class="fa fa-envelope"></a></li>


      </ul>
    
  </section>

  
  <section class="recent-posts">
    <div class="mini-posts">
      <header>
        <h3>Recent Posts</h3>
      </header>
      <div class="posts-container">
        

        
          
        

        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/fastdfs%E9%85%8D%E7%BD%AE%E5%8F%8A%E4%BB%8B%E7%BB%8D/">FastDFS配置及介绍</a>
              </h3>
              
              <time class="published" datetime='2020-08-27'>
                August 27, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/orm%E5%B8%B8%E8%A7%84%E6%93%8D%E4%BD%9C%E9%87%8D%E7%82%B9/">orm常规操作</a>
              </h3>
              
              <time class="published" datetime='2020-07-28'>
                July 28, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98%E6%93%8D%E4%BD%9C/">支付宝沙箱支付操作</a>
              </h3>
              
              <time class="published" datetime='2020-07-28'>
                July 28, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/%E8%85%BE%E8%AE%AF%E7%9F%AD%E4%BF%A1%E5%8F%91%E9%80%81%E9%AA%8C%E8%AF%81%E7%A0%81/">腾讯短信发送验证码</a>
              </h3>
              
              <time class="published" datetime='2020-07-28'>
                July 28, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/flask&#43;vue%E5%AE%9E%E7%8E%B0%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB/">flask&#43;vue实现前后端分离</a>
              </h3>
              
              <time class="published" datetime='2020-07-26'>
                July 26, 2020
              </time>
            </header>
            

          </article>
        
      </div>

      
        <a href=
          
            /blog/
          
        class="button">View more posts</a>
      
    </div>
  </section>

  
  
  
  
  
    <section id="categories">
      <header>
        <h3>
          <a href="/blog/categories/">Categories</a>
        </h3>
      </header>
        
          
        

        
        <p>
          <article>
            <header>
              
                <a href="/blog/categories/hugo/">hugo</a>
                <span style="float:right;">43</span>
              
            </header>
          </article>
        </p>
        
    </section>
  
  

  
  
    <section id="mini-bio">
      <h3>About</h3>
      <p>blog于2018年6月10日创建(It was created on May 10, 2020),文章主要介绍了python的一些常用框架和库及它们的一些用法</p>
      <a href="/blog/about/" class="button">Learn More</a>
    </section>
  

  
  <section id="footer">
    
      <ul class="icons">
        
          
    <li><a href="/blog/blog/index.xml" type="application/rss+xml" target="_blank" title="RSS" class="fa fa-rss"></a></li>


        
        












































































  <li><a href="mailto:2980738482@qq.com" title="Email" class="fa fa-envelope"></a></li>


      </ul>
    
    <p class="copyright">
      
        &copy; 2020
        
          mff blog
        
      .
      Powered by <a href="//gohugo.io" target="_blank">Hugo</a>
    </p>
  </section>
</section>

    </div>
    <a id="back-to-top" href="#" class="fa fa-arrow-up fa-border fa-2x"></a>
    

    
      
    

    
      
      
      
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/highlight.min.js"></script>
        
        
        
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/languages/r.min.js"></script>
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/languages/yaml.min.js"></script>
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/languages/css.min.js"></script>
        <script>hljs.configure({languages: []}); hljs.initHighlightingOnLoad();</script>
      
    
    
    
      <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/skel/3.0.1/skel.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.25/jquery.fancybox.min.js"></script>
      <script src="/blog/js/util.js"></script>
      <script src="/blog/js/main.js"></script>
      <script src="/blog/js/backToTop.js"></script>
    

    
      
        
      
    

    
    <script>hljs.initHighlightingOnLoad();</script>
      <script src="//yihui.name/js/math-code.js"></script>
<script async
src="//cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML">
</script>


  </body>
</html>

